#! /usr/bin/env python3

import argparse

from sys import argv

from plenum.common.script_helper import isNodeType, exportNodeGenTxn, exportStewardGenTxn, buildKeepDirIfNotExists
from plenum.common.config_util import getConfig


if __name__ == "__main__":
    config = getConfig()

    buildKeepDirIfNotExists(config.baseDir)

    parser = argparse.ArgumentParser(
        description="Export keys")

    parser.add_argument('name', action="store")
    parser.add_argument('--print_gen_txn', help='overrides keys',
                        action='store_true')

    args = parser.parse_args()
    name = argv[1]

    isNode = isNodeType(config.baseDir, name)
    if isNode:
        exportNodeGenTxn(config.baseDir, args.print_gen_txn, name)
    else:
        exportStewardGenTxn(config.baseDir, args.print_gen_txn, name)
